{template 'web/_header'}
{template 'web/shop/tabs'}

{if $operation == 'post'}
<div class="main">
    
    <form  {ife 'shop.category' $item}action="" method="post"{/if} class="form-horizontal form" enctype="multipart/form-data" >
    
        <div class="panel panel-default">
            <div class="panel-heading">
                商品分类
            </div>
            <div class="panel-body">
                
                {if !empty($item)}
                 <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类连接(点击复制)</label>
                <div class="col-sm-9 col-xs-12">
                    <p class='form-control-static'><a href='javascript:;' title='点击复制连接' id='cp'>
                           {if empty($parent)}
                           {php echo $this->createMobileUrl('shop/list',array('pcate'=>$item['id']))}
                           {else}
                               {if empty($parent1)}
                                 {php echo $this->createMobileUrl('shop/list',array('ccate'=>$item['id']))}
                               {else}
                                 {php echo $this->createMobileUrl('shop/list',array('tcate'=>$item['id']))}
                               {/if}
                           {/if}
                        </a>
                    </p>
                </div>
            </div>
                {/if}
                
                {if !empty($parentid)}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类</label>
                    <div class="col-sm-9 col-xs-12 control-label" style="text-align:left;">
                        {if !empty($parent1)}{$parent1['name']} >> {/if}
                        {$parent['name']}</div>
                </div>
                {/if}
                
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'shop.category' $item}
                           <input type="text" name="displayorder" class="form-control" value="{$item['displayorder']}" />
                        {else}
                           <div class='form-control-static'>{$item['displayorder']}</div>
                        {/if}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>分类名称</label>
                    <div class="col-sm-9 col-xs-12">
                         {ife 'shop.category' $item}
                        <input type="text" name="catename" class="form-control" value="{$item['name']}" />
                           {else}
                           <div class='form-control-static'>{$item['name']}</div>
                        {/if}
                    </div>
                </div>
               {if !empty($parentid)}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类图片</label>
                    <div class="col-sm-9 col-xs-12">
                      {ife 'shop.category' $item}
                             {php echo tpl_form_field_image('thumb', $item['thumb'])}
                            <span class="help-block">建议尺寸: 100*100，或正方型图片 </span>
                        {else}
                            {if !empty($item['thumb'])}
                                  <a href='{php echo tomedia($item['thumb'])}' target='_blank'>
                                <img src="{php echo tomedia($item['thumb'])}" style='width:100px;border:1px solid #ccc;padding:1px' />
                                  </a>
                            {/if}
                        {/if}
                    </div>
                </div>
               {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类描述</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'shop.category' $item}
                        <textarea name="description" class="form-control" cols="70">{$item['description']}</textarea>
                        {else}
                         <div class='form-control-static'>{$item['description']}</div>
                        {/if}
                        
                    </div>
                </div> 
               {if $level<=2}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类广告</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'shop.category' $item}
                        {php echo tpl_form_field_image('advimg', $item['advimg'])}
                        <span class="help-block">建议尺寸: 640*320</span>
                         {else}
                           {if !empty($item['advimg'])}
                                 <a href='{php echo tomedia($item['advimg'])}' target='_blank'>
                                <img src="{php echo tomedia($item['advimg'])}" style='width:100px;border:1px solid #ccc;padding:1px' />
                                 </a>
                           {/if}
                        {/if}
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类广告链接</label>
                    <div class="col-sm-9 col-xs-12">
                         {ife 'shop.category' $item}
                        <input type="text" name="advurl" class="form-control" value="{$item['advurl']}" />
                        {else}
                         <div class='form-control-static'>{$item['advurl']}</div>
                         {/if}
                    </div>
                </div>
               {/if}
               {if !empty($parentid)}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否推荐</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'shop.category' $item}
                        <label class='radio-inline'>
                            <input type='radio' name='isrecommand' value=1' {if $item['isrecommand']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='isrecommand' value=0' {if $item['isrecommand']==0}checked{/if} /> 否
                        </label>
                            {else}
                           <div class='form-control-static'>{if empty($item['isrecommand'])}否{else}是{/if}</div>
                           {/if}
                    </div> 
                </div>
               <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">首页推荐</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'shop.category' $item}
                        <label class='radio-inline'>
                            <input type='radio' name='ishome' value=1' {if $item['ishome']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='ishome' value=0' {if $item['ishome']==0}checked{/if} /> 否
                        </label>
                           {else}
                           <div class='form-control-static'>{if empty($item['ishome'])}否{else}是{/if}</div>
                           {/if}
                    </div> 
                </div>
                {/if}  
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'shop.category' $item}
                        <label class='radio-inline'>
                            <input type='radio' name='enabled' value=1' {if $item['enabled']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='enabled' value=0' {if $item['enabled']==0}checked{/if} /> 否
                        </label>
                          {else}
                           <div class='form-control-static'>{if empty($item['enabled'])}否{else}是{/if}</div>
                           {/if}
                    </div>
                </div>
                
                 <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                           {ife 'shop.category' $item}
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" onclick="return formcheck()" />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ifp 'shop.category.add|shop.category.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default col-lg-1" />
                    </div>
            </div>
                
            </div>
        </div>
      
    </form>
</div>
<script language='javascript'>
         require(['util'],function(u){
    $('#cp').each(function(){
	u.clip(this, $(this).text());
	});
    })
    $('form').submit(function(){
        if($(':input[name=catename]').isEmpty()){
            Tip.focus(':input[name=catename]','请输入分类名称!');
            return false;
        }
        return true;
    });
</script>
{elseif $operation == 'display'}
<script language="javascript" src="../addons/sz_yi/static/js/dist/nestable/jquery.nestable.js"></script>
<link rel="stylesheet" type="text/css" href="../addons/sz_yi/static/js/dist/nestable/nestable.css" />
<style type='text/css'>
    .dd-handle { height: 40px; line-height: 30px}
</style>
<div class="main">
    <div class="category">
        <form action="" method="post">
            <div class="panel panel-default">
                <div class="panel-body table-responsive">

                        <div class="dd" id="div_nestable">
                            <ol class="dd-list">

                               {loop $category $row}
                                 {if empty($row['parentid'])}
                                <li class="dd-item" data-id="{$row['id']}">

                                    <div class="dd-handle"  style='width:100%;'>
                                        [ID: {$row['id']}] {$row['name']} 
                                        <span class="pull-right">
                                            {ifp 'shop.category.add'}<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('parentid' => $row['id'], 'op' => 'post'))}" title='添加子分类' ><i class="fa fa-plus"></i></a>{/if}
                                            {ifp 'shop.category.edit|shop.category.view'}
                                             <a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('id' => $row['id'], 'op' => 'post'))}" title="{ifp 'shop.category.edit'}修改{else}查看{/if}" ><i class="fa fa-edit"></i></a>
                                            {/if}
                                            {ifp 'shop.category.delete'}<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('id' => $row['id'], 'op' => 'delete'))}" title='删除' onclick="return confirm('确认删除此分类吗？');return false;"><i class="fa fa-remove"></i></a>{/if}
                                        </span>
                                    </div>
                                    {if count($children[$row['id']])>0}
                                    
                                    <ol class="dd-list"  style='width:100%;'>
                                        {loop $children[$row['id']] $child}
                                        <li class="dd-item" data-id="{$child['id']}">
                                            <div class="dd-handle">
                                                <img src="{php echo tomedia($child['thumb']);}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' /> &nbsp;
                                                [ID: {$child['id']}] {$child['name']}
                                                <span class="pull-right">
                                                    {if intval($shopset['catlevel'])==3}
                                                     {ifp 'shop.category.add'}<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('parentid' => $child['id'], 'op' => 'post'))}" title='添加子分类' ><i class="fa fa-plus"></i></a>{/if}
                                                     {/if}
                                                      {ifp 'shop.category.edit|shop.category.view'}<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('id' => $child['id'], 'op' => 'post'))}" title="{ifp 'shop.category.edit'}修改{else}查看{/if}" ><i class="fa fa-edit"></i></a>{/if}
                                                      {ifp 'shop.category.delete'} <a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('id' => $child['id'], 'op' => 'delete'))}" title='删除' onclick="return confirm('确认删除此分类吗？');return false;"><i class="fa fa-remove"></i></a>{/if}
                                                </span>
                                            </div>
                                                  {if count($children[$child['id']])>0 && intval($shopset['catlevel'])==3}

                                                    <ol class="dd-list"  style='width:100%;'>
                                                        {loop $children[$child['id']] $third}
                                                        <li class="dd-item" data-id="{$third['id']}">
                                                            <div class="dd-handle">
                                                                <img src="{php echo tomedia($third['thumb']);}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' /> &nbsp;
                                                                [ID: {$third['id']}] {$third['name']}
                                                                <span class="pull-right">
                                                                        {ifp 'shop.category.edit|shop.category.view'}<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('id' => $third['id'], 'op' => 'post'))}" title="{ifp 'shop.category.edit'}修改{else}查看{/if}" ><i class="fa fa-edit"></i></a>{/if}
                                                                      {ifp 'shop.category.delete'}<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('shop/category', array('id' => $third['id'], 'op' => 'delete'))}" title='删除' onclick="return confirm('确认删除此分类吗？');return false;"><i class="fa fa-remove"></i></a>{/if}
                                                                </span>
                                                            </div>
                                                        </li>
                                                        {/loop}
                                                    </ol>
                                                    {/if}
                                        </li>
                                        {/loop}
                                    </ol>
                                    {/if}
                                    
                                </li>
                                {/if}
                              {/loop}
                                
                            </ol>
                            <table class='table'>
                                <tr>
                                <td>
                                    {ifp 'shop.category.add'}
                                    <a href="{php echo $this->createWebUrl('shop/category',array('op' => 'post'))}" class="btn btn-default"><i class="fa fa-plus"></i> 添加新分类</a>
                                    {/if}
                                    {ifp 'shop.category.edit'}
                                    <input id="save_category" type="button" class="btn btn-primary" value="保存分类修改">
                                    {/if}
                                    <input type="hidden" name="token" value="{$_W['token']}" />
                                    <input type="hidden" name="datas" value="" />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </form>
    </div>
</div>
    <script language='javascript'>
     
      
      
    $(function(){
      var depth = {php echo intval($shopset['catlevel'])};
      if(depth<=0) {
          depth =2;
      }
      $('#div_nestable').nestable({maxDepth: depth });
         
        $(".dd-handle a,dd-handle embed,dd-handle div").mousedown(function (e) {
            e.stopPropagation();
        }); 
        var $expand = false;
        $('#nestableMenu').on('click', function(e)
        {
            if ($expand) {
                $expand = false;
                $('.dd').nestable('expandAll');
            }else {
                $expand = true;
                $('.dd').nestable('collapseAll');
            }
        });
        
        $("#save_category").click(function(){
             var json = window.JSON.stringify($('#div_nestable').nestable("serialize"));
             $(':input[name=datas]').val(json);
             $('form').submit();
        })
        
    })
    </script>
 
{/if}
{template 'web/_footer'}

